<%-- 
    Document   : trade.fixation.contract.ajax-source
    Created on : Dec 14, 2012, 3:15:34 PM
    Author     : kiendn
--%>

<%@page import="pc.util.Utils"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="wstrader.task.trade.fixation.Contract"%>
<%@page import="wstrader.Trader"%>
<%@page import="wstrader.Users"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%
            int BuyerSellerId = Integer.parseInt(request.getParameter("buyer_seller"));
            String TerminalMarket = request.getParameter("terminal_market");
            String TerMth = request.getParameter("ter_mth");
            String Type = request.getParameter("cnt_type");
            int status = Integer.parseInt(request.getParameter("status"));
            Users usr = Trader.getUser(request.getParameter("uid"));

            Contract task = usr.trade.fixation.contract;

            if (TerminalMarket.compareTo("") == 0) {
                TerminalMarket = "0";
            }
            if (Type.compareTo("") == 0) {
                Type = "0";
            }
            String Sql = "Select * from contracts where "
                    + "(supplier_buyer_id = " + BuyerSellerId + " OR " + (BuyerSellerId == 0) + ") "
                    + "and (terminal_market = '" + TerminalMarket + "' OR " + (TerminalMarket.equals("0")) + ") "
                    + "and (terminal_month = '" + TerMth + "' OR " + (TerMth.equals("1970-01-01")) + ") "
                    + "and (type = '" + Type + "' OR " + (Type.equals("0")) + ") "
                    + "and (status = " + status + " OR " + (status == 0) + ") "
                    + "and (contract_price_type = 'U') order by contracts.id desc";
            ResultSet Rs = task.getSQLCommand().executeQuery(Sql);

            String R_id = "";
            String Colour = "";
            float pending = 0;
            float unfixed = 0;
            int dLoop = 0;
        %>
        <link href="styles/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>
        <link href="styles/demo_table_jui.css" rel="stylesheet" type="text/css"/>
        <style type="text/css">

            .style3 {
                font-family: Arial;
                font-size: 12px;
            }

        </style>
    </head>
    <body>
        <table id="mytable" style="width: 100% !important">
            <thead>
                <tr>
                    <th align="center"><strong><span class="style29 style3 style6">Id</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Contract No</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Contract Ref</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Buyer/Seller</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Market</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Month</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Bot/Sold</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Differential</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Average Price</span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Lots Fixed </span></strong></th>
                    <th align="center"><strong><span class="style29 style3 style6">Lots UnFixed </span></strong></th>
                </tr>
            </thead>
            <tbody>
                <%
                    while (Rs.next()) {
                        //R_id = Rs.getInt("id");
                        pending = Rs.getFloat("Tons") - Rs.getFloat("receive_tons");
                        unfixed = Rs.getFloat("unfixed_tons");
                        if (unfixed > 0) {
                            Colour = "#FF0000";
                        }
                        if (unfixed == 0) {
                            Colour = "#000000";
                        }
                %>
                <tr id="<%=Rs.getInt("id")%>" onDblClick="cardViewClick(this);" onClick="highlightOn(this);">
                    <td align="center"><span class="style3"><%=Rs.getInt("id")%></span></td>
                    <td style="color:<%=Colour%>" align="center"><span class="style3"><%=Rs.getString("ref_number")%></span></td>		  
                    <td style="color:<%=Colour%>" align="center"><span class="style3"><%=Rs.getString("contract_no")%></span></td>
                    <td align="left"><span class="style3"><%=task.getFieldValueForId("company_master", "name", Rs.getInt("supplier_buyer_id"))%></span></td>
                    <td align="left"><span class="style3"><%=Rs.getString("terminal_market")%></span></td>
                    <%
                        String TM = "";
                        if (Rs.getDate("terminal_month") == null) {
                            TM = "-";
                        }
                        if (Rs.getDate("terminal_month") != null) {
                            TM = Utils.dateToStr(Rs.getDate("terminal_month")).substring(3);
                        }
                    %>
                    <td align="left"><span class="style3"><%=TM%></span></td>
                    <td align="center"><span class="style3"><%=Rs.getString("type")%></span></td>
                    <td align="right"><span class="style3"><%=Utils.numberToStr(Rs.getFloat("differential"), 0)%></span></td>
                    <td align="right"><span class="style3"><%=Utils.numberToStr(Rs.getFloat("contract_price_foreign"), 2)%></span></td>
                    <%
                        if (Rs.getString("terminal_market").compareTo("LIFFE") == 0) {
                    %>
                    <td align="right"><span class="style3"><%=Utils.numberToStr(Rs.getFloat("fixed_tons") / 10, 0)%></span></td>		  
                    <td width="10%" align="right"><span class="style3"><%=Utils.numberToStr(Rs.getFloat("unfixed_tons") / 10, 0)%></span></td>
                    <%
                    } else {
                    %>
                    <td align="right"><span class="style3"><%=Utils.numberToStr(Rs.getFloat("fixed_tons") / 17.01, 0)%></span></td>		  
                    <td align="right"><span class="style3"><%=Utils.numberToStr(Rs.getFloat("unfixed_tons") / 17.01, 0)%></span></td>
                    <%
                        }
                    %>		  
                </tr>
                <%
                        dLoop = dLoop + 1;
                    }
                %>
            </tbody>
            <tfoot>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
            <th align="center"></th>
        </tfoot>
    </table>
    <script type="text/javascript">
        $(document).ready(function(){
            oTable = $("#mytable").dataTable({
                "sScrollY": 250,
                "bJQueryUI": true,
                "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
                "sPaginationType": "full_numbers"
            });
        });
    </script>
</body>
</html>
